import 'package:share_fit/app/controllers/base/base_controller.dart';
import 'package:share_fit/app/ute/uteped_const.dart';

import 'weight_setting_state.dart';

class WeightSettingLogic extends BaseController {
  final WeightSettingState state = WeightSettingState();
  static const methodSetWeightSyncEnable = "setWeightSyncEnable";

  void setWeightSyncEnable(value) {
    state.isWeightSyncEnable.value = value;
    bRemoteReqAsync(methodSetWeightSyncEnable, {UTEPedConst.keyEnable: value})
        .then((success) => _onSetWeightSyncEnable(success, value));
  }

  void _onSetWeightSyncEnable(success, value) {
    if (success) {
      save(methodSetWeightSyncEnable, value);
    }
    else {
      state.isWeightSyncEnable.value = !value;
    }
  }

  @override
  String getRemotePath() {
    return UTEPedConst.pathDeviceOptions;
  }

  @override
  String getStoragePath() {
    return UTEPedConst.pathDevice;
  }

  @override
  void initState() {
    state.isWeightSyncEnable.value = read(methodSetWeightSyncEnable, defaultValue: false);
  }

  @override
  void onRemoteEvent(event, method) {
    // TODO: implement onRemoteEvent
  }
}
